package com.ruoyi.web.controller.mes;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.domain.MesMakeversionDetail;
import com.ruoyi.web.domain.MesPlatemakingDetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.MesPlatemaking;
import com.ruoyi.web.service.IMesPlatemakingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 制版管理Controller
 * 
 * @author wxt
 * @date 2024-02-03
 */
@Api("制版管理")
@RestController
@RequestMapping("/mes/platemaking")
public class MesPlatemakingController extends BaseController
{
    @Autowired
    private IMesPlatemakingService mesPlatemakingService;

    /**
     * 查询制版表列表
     */
    @ApiOperation("查询制版表列表")
    @GetMapping("/list")
    public TableDataInfo list(MesPlatemaking mesPlatemaking)
    {
        startPage();
        List<MesPlatemaking> list = mesPlatemakingService.selectMesPlatemakingList(mesPlatemaking);
        return getDataTable(list);
    }

    /**
     * 导出制版表列表
     */
    @ApiOperation("导出制版表列表")
    @Log(title = "制版表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesPlatemaking mesPlatemaking)
    {
        List<MesPlatemaking> list = mesPlatemakingService.selectMesPlatemakingList(mesPlatemaking);
        ExcelUtil<MesPlatemaking> util = new ExcelUtil<MesPlatemaking>(MesPlatemaking.class);
        util.exportExcel(response, list, "制版表数据");
    }

    /**
     * 获取制版表详细信息
     */
    @ApiOperation("获取制版表详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mesPlatemakingService.selectMesPlatemakingById(id));
    }


    @ApiOperation("制版明细查询")
    @PostMapping(value = "/DetailList")
    public TableDataInfo getDetailList(@RequestBody Map<String,String> params)
    {
        startPage(params);
//        if(StringUtils.isNotEmpty(params.get("type"))&&params.get("type").equals("1")){//制版
//            params.put("replenishWhere","1=2");//不需要查询取版的数据
//
//        }else if(StringUtils.isNotEmpty(params.get("type"))&&params.get("type").equals("2")){//取版
//            params.put("plateMakingWhere","1=2");//不需要查询制版的数据
//        }
        MesPlatemakingDetail detail=new MesPlatemakingDetail();
        detail.setWhere(params);
        List<MesPlatemakingDetail> list = mesPlatemakingService.getDetailList(detail);
        return getDataTable(list);
    }

    @ApiOperation("导出制版明细")
    @Log(title = "制版明细表", businessType = BusinessType.EXPORT)
    @PostMapping("/detailexport")
    public void detailexport(HttpServletResponse response, @RequestBody Map<String,String> params)
    {
        MesPlatemakingDetail detail=new MesPlatemakingDetail();
        detail.setWhere(params);
        List<MesPlatemakingDetail> list = mesPlatemakingService.getDetailList(detail);
        ExcelUtil<MesPlatemakingDetail> util = new ExcelUtil<MesPlatemakingDetail>(MesPlatemakingDetail.class);
        util.exportExcel(response, list, "制版明细数据");
    }

    /**
     * 新增制版表
     */
    @ApiOperation("新增制版表")
    @Log(title = "制版表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesPlatemaking mesPlatemaking)
    {
        return toAjax(mesPlatemakingService.insertMesPlatemaking(mesPlatemaking));
    }

    /**
     * 修改制版表
     */
    @ApiOperation("修改制版表")
    @Log(title = "制版表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesPlatemaking mesPlatemaking)
    {
        return toAjax(mesPlatemakingService.updateMesPlatemaking(mesPlatemaking));
    }

    /**
     * 删除制版表
     */
    @ApiOperation("删除制版表")
    @Log(title = "制版表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mesPlatemakingService.deleteMesPlatemakingByIds(ids));
    }
}
